/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AlteraSenha.java
 *
 * Created on 20/09/2010, 08:11:29
 */

package view.sistema;

import javax.swing.JOptionPane;
import model.sistema.LoginDao;

/**
 *
 * @author Administrador
 */
public class AlteraSenha extends javax.swing.JDialog {

    /** Creates new form AlteraSenha */
    public AlteraSenha(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jpt_senha_antiga = new javax.swing.JPasswordField();
        jLabel2 = new javax.swing.JLabel();
        jpt_nova_senha = new javax.swing.JPasswordField();
        jLabel3 = new javax.swing.JLabel();
        jpt_confirma = new javax.swing.JPasswordField();
        jbt_ok = new javax.swing.JButton();
        jbt_cancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Senhas");

        jLabel1.setText("Senha Antiga: ");

        jLabel2.setText("Nova Senha: ");

        jLabel3.setText("Confirmar nova senha: ");

        jbt_ok.setText("Ok");
        jbt_ok.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbt_okActionPerformed(evt);
            }
        });

        jbt_cancel.setText("Cancel");
        jbt_cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbt_cancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jpt_senha_antiga, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jpt_nova_senha, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jpt_confirma, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jbt_ok)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbt_cancel)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpt_senha_antiga, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpt_nova_senha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpt_confirma, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbt_ok)
                    .addComponent(jbt_cancel))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-154)/2, (screenSize.height-234)/2, 154, 234);
    }// </editor-fold>//GEN-END:initComponents

    private void jbt_okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbt_okActionPerformed
        String s = jpt_senha_antiga.getText();
        String senha = jpt_nova_senha.getText();
        String confirma = jpt_confirma.getText();
        if(senha.compareTo(confirma) != 0)
        {
            JOptionPane.showMessageDialog(null, "Nova senha não confere!","Alteração de senha",0);
            return;
        }
        try
        {
            new LoginDao().alteraSenha(s, senha);
            
        }catch(Exception e)
        {
            JOptionPane.showMessageDialog(null, e.getMessage(),"Erro desconhecido",0);
        }
        dispose();
    }//GEN-LAST:event_jbt_okActionPerformed

    private void jbt_cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbt_cancelActionPerformed
            dispose();
    }//GEN-LAST:event_jbt_cancelActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                AlteraSenha dialog = new AlteraSenha(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JButton jbt_cancel;
    private javax.swing.JButton jbt_ok;
    private javax.swing.JPasswordField jpt_confirma;
    private javax.swing.JPasswordField jpt_nova_senha;
    private javax.swing.JPasswordField jpt_senha_antiga;
    // End of variables declaration//GEN-END:variables

}
